<template>
	<el-container>
		<el-header>
			商城设置
		</el-header>
		<el-main style="background-color: #FFF">
			<el-form :model="form" ref="configForm" label-width="100px" label-position="left">
				<el-form-item label="热门搜索">
					<sc-form-table v-model="form.hotSearchs" dragSort :addTemplate="{ keyword: '' }" placeholder="暂无数据">
						<el-table-column prop="code" label="关键词" width="350">
							<template #default="scope">
								<el-input v-model="scope.row.keyword" placeholder="关键词"></el-input>
							</template>
						</el-table-column>
					</sc-form-table>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit">保 存</el-button>
				</el-form-item>
			</el-form>
		</el-main>
	</el-container>
</template>

<script>
export default {
		name: 'shop-config',
		components: {

		},
		data() {
			return {
				form: {
					hotSearchs: [],
				},
			}
		},
		mounted() {
			this.getConfigData()
		},
		methods: {
			onSubmit() {
				this.$API.shop.config.update(this.form).then((res) => {
					if (res.code === 0) {
						this.$message.success('保存成功');
					}
					else {
						this.$message.error('保存失败,' + res.message);
					}
				})
			},
			getConfigData() {
				const that = this;
				this.$API.shop.config.info().then(res => {
					console.log(res);
					if (res.code === 0) {
						that.form = res.data;
					}
					else {
						this.$message.error('getConfigData 获取数据失败,' + res.message);
					}

				});
			},
		}
	}
</script>

<style>
</style>
